using System.Collections.Generic;
using System.Reflection;
using Sixeyed.CodeGeneration.Metadata.Bases;
using Sixeyed.CodeGeneration.Metadata.Interfaces;
using Sixeyed.CodeGeneration.Metadata.Wsdl.Interfaces;
using Sixeyed.CodeGeneration.Metadata.Wsdl.Items;
using Sixeyed.CodeGeneration.Metadata.Wsdl.Providers.Bases;

namespace Sixeyed.CodeGeneration.Metadata.Wsdl.Providers
{
    /// <summary>
    /// Provider for returning <see cref="WebMethod"/> metadata items
    /// </summary>
    /// <remarks>
    /// Provider shows all available methods from the Web service endpoint.
    /// Method name (SOAP action) is used as the key for the metadata item.
    /// </remarks>
    public class WebMethodProvider : WsdlProviderBase
    {
        /// <summary>
        /// Gets the provider name
        /// </summary>
        public override string Name
        {
            get { return "Web Method Provider"; }
        }

        /// <summary>
        /// Gets the provider description
        /// </summary>
        public override string Description
        {
            get { return "Retrieves metadata representing a Web Method"; }
        }

        /// <summary>
        /// Gets the name of the returned metadata item type
        /// </summary>
        public override string ItemTypeName
        {
            get { return "Web Method"; }
        }

        /// <summary>
        /// Returns a list of available Web methods
        /// </summary>
        /// <returns>List of Web methods</returns>
        public override List<string> GetItemNames()
        {
            return this._source.GetWebMethodNames();
        }

        /// <summary>
        /// Returns a populated metadata item
        /// </summary>
        /// <param name="itemKey">Web method name</param>
        /// <returns>Populated <see cref="WebMethod"/></returns>
        public override IMetadataItem GetItem(string itemKey)
        {
            WebMethod item = this.CreateItem<WebMethod>(itemKey);
            MethodInfo methodInfo = this._source.GetWebMethod(itemKey);
            item.TypedItem = methodInfo;
            return item;
        }
    }
}
